import yaml
class hyaml:
   def create_yml(self,filename,data):
      with open(filename, 'w', encoding='utf-8') as f:
         yaml.dump(data=apiData, stream=f, allow_unicode=True)


   def show_yml(self):
      with open('./test_create1.yml', 'r', encoding='utf-8') as f:
         result = yaml.load(f.read(), Loader=yaml.FullLoader)
         print(result, type(result))
         return result

if __name__ == '__main__':
   myyaml=hyaml()
   apiData = {
      "page": 1,
      "msg": "地址",
      "data": [{
         "id": 1,
         "name": "学校"
      }, {
         "id": 2,
         "name": "公寓"
      }, {
         "id": 3,
         "name": "流动人口社区"
      }],
   }
   filename="nginx"
   myyaml.create_yml(filename+'.yaml',apiData)
   myyaml.show_yml()
